package com.baizhi.service.impl;

import java.util.List;

import com.baizhi.dao.AddressDao;
import com.baizhi.entity.Address;
import com.baizhi.service.AddressService;
import com.baizhi.util.MyBatisUtil;

public class AddressServiceImpl implements AddressService {
	private AddressDao ad = null;
	@Override
	public List<Address> findAddressByUserId(Integer userid) {
		ad = MyBatisUtil.getMapper(AddressDao.class);
		return ad.selectAddressesByUserId(userid);
	}

	@Override
	public Address findAddressById(Integer id) {
		ad = MyBatisUtil.getMapper(AddressDao.class);
		return ad.selectAddressById(id);
	}

	@Override
	public int addAddress(Address address) {
		ad = MyBatisUtil.getMapper(AddressDao.class);
		int i = ad.insertAddress(address);
		int ii = 0;
		if(i != 0){
			ii = address.getAddressid();
			if(ii != 0){
				//添加地址成功
				MyBatisUtil.commit();
			}
		}else{
			//添加失败
			MyBatisUtil.rollback();
		}
		return ii;
	}

}
